package com.pms.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pms.entity.Goal;
import com.pms.entity.Task;
import com.pms.service.GoalService;
import com.pms.service.TaskService;
import com.pms.util.GetSession;

public class ToTask extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String goalId = request.getParameter("goalId");
		if(goalId == null){
			Goal goal1 = (Goal)GetSession.getSession(request).getAttribute("goal");
			goalId = goal1.getGoal_id();
		}
		GoalService goalService = new GoalService();
		Goal goal = goalService.findGoalById(goalId);
		GetSession.getSession(request).setAttribute("goal", goal);

		TaskService taskServ = new TaskService();

		List<Task> list = taskServ.findAllTaskByGoalId(goalId);
		double rate = 0;
		rate = taskServ.rate(goalId);
		if(rate != 0){
			request.setAttribute("rate", rate);
		}
		request.setAttribute("taskList", list);
		request.getRequestDispatcher("/WEB-INF/task.jsp").forward(request,
				response);
	}

}
